<script setup lang="ts">
import { ref } from 'vue'
import axios from 'axios';
import {useRouter} from 'vue-router'
const router = useRouter();
const username = ref('');
const password = ref('');

function doLogin(){
    var options = {
        url: 'api/login',
        data: {
            username: username.value,
            password: password.value,
        },
        method: 'POST',
        headers:{'Content-Type':'application/x-www-form-urlencoded'}
    }
    console.log(username.value);
    console.log(password.value);
    
    axios(options).then((res: any)=>{
        console.log(res);
        if(res.data === "登录成功"){
            router.push('/')
        }else{
            alert("登录失败，请检查账号密码！")
        }
    })
}
</script>

<template>
登录页面<br>
用户名：<input type="text" v-model="username"><br>
密码：<input type="text" v-model="password"><br>
<button @click="doLogin">登录</button>
</template>

<style scoped>
</style>
